//
//  DCFinishedCell.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/11/29.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCFinishedCell.h"
CGFloat cellHeight = 130;
@interface DCFinishedCell ()
@property (nonatomic,strong) DCImageAndTextLabel *startLabel;
@property (nonatomic,strong) DCImageAndTextLabel *extractLabel;
@property (nonatomic,strong) DCImageAndTextLabel *endLabel;
@property (nonatomic,strong) DCImageAndTextLabel *sendLabel;

@property (nonatomic,strong) DCImageAndTextLabel *carLabel;
@property (nonatomic,strong) UILabel *totalNumLabel;
@property (nonatomic,strong) UILabel *numLabel;

@property (nonatomic,strong) UIButton *tapBtn;
@end
@implementation DCFinishedCell
+ (CGFloat)getCellHeight
{
    return cellHeight;
}
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *CellID = @"Cell";
    DCFinishedCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[DCFinishedCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}
-(void)setUpUI
{
    DCImageAndTextLabel *startLabel = [[DCImageAndTextLabel alloc]init];
    startLabel.imageView.image = IMAGENAME(@"起点");
    self.startLabel = startLabel;
    [self addSubview:startLabel];
    
    DCImageAndTextLabel *extractLabel = [[DCImageAndTextLabel alloc]init];
    extractLabel.imageView.image = IMAGENAME(@"提现");
    self.extractLabel = extractLabel;
    [self addSubview:extractLabel];
    
    DCImageAndTextLabel *endLabel = [[DCImageAndTextLabel alloc]init];
    endLabel.imageView.image = IMAGENAME(@"终点");
    self.endLabel = endLabel;
    [self addSubview:endLabel];
    
    DCImageAndTextLabel *sendLabel = [[DCImageAndTextLabel alloc]init];
    sendLabel.imageView.image = IMAGENAME(@"送");
    self.sendLabel = sendLabel;
    [self addSubview:sendLabel];
    
    self.carLabel = [[DCImageAndTextLabel alloc]init];
    self.carLabel.imageView.image = IMAGENAME(@"立方体");
    //    self.carLabel.textLabel.font = FONT(16);
    [self addSubview:self.carLabel];
    
    self.totalNumLabel = [self getLabelWithFont:14 textAlignment:NSTextAlignmentRight];
    [self addSubview:self.totalNumLabel];
    
    self.numLabel = [self getLabelWithFont:12 textAlignment:NSTextAlignmentLeft];
    self.numLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:self.numLabel];
    
    UIButton *tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [tapBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [tapBtn setTitleColor:BlueColor forState:UIControlStateNormal];
    tapBtn.titleLabel.font = FONT(15);
    tapBtn.layer.cornerRadius = 15;
    tapBtn.clipsToBounds = YES;
    tapBtn.layer.borderColor = BlueColor.CGColor;
    tapBtn.layer.borderWidth = 1;
    tapBtn.tag = 0;
    self.tapBtn = tapBtn;
    [self addSubview:tapBtn];
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat kBaseHeight = 30;
    self.startLabel.frame = CGRectMake(30, 0, (self.width - 30)/3, kBaseHeight);
    self.extractLabel.frame = CGRectMake(self.startLabel.right, 0, (self.width - 30)*2/3, self.startLabel.height);
    self.endLabel.frame = CGRectMake(self.startLabel.x, self.startLabel.bottom, self.startLabel.width, self.startLabel.height);
    self.sendLabel.frame = CGRectMake(self.extractLabel.x, self.endLabel.y, self.extractLabel.width, self.startLabel.height);
    
    self.carLabel.frame = CGRectMake(20, self.sendLabel.bottom, 100*WIDTHSCALE6, kBaseHeight);
    self.totalNumLabel.frame = CGRectMake(self.carLabel.right, self.carLabel.y, 80*WIDTHSCALE6, self.carLabel.height);
    self.numLabel.frame = CGRectMake(self.totalNumLabel.right, self.carLabel.y, self.width - self.carLabel.width - self.totalNumLabel.width, self.carLabel.height);
    
    self.tapBtn.size = CGSizeMake(80*WIDTHSCALE6, kBaseHeight);
    self.tapBtn.x = self.width - self.tapBtn.width  - 10;
    self.tapBtn.y = self.numLabel.bottom+5;
    
    self.tapBtn.height = [self.model.isTransportUpload integerValue] == 2?0:kBaseHeight;

    cellHeight = [self.model.isTransportUpload integerValue] == 2?100:130;
}

-(void)setModel:(DCOrderReceiveOddModel *)model
{
    _model = model;
    self.startLabel.textLabel.text = model.startCity;
    self.extractLabel.textLabel.text = [model.startAddress cutStrWithLength:10];
    self.endLabel.textLabel.text = model.endCity;
    self.sendLabel.textLabel.text = [model.endAddress cutStrWithLength:10];
    
    self.carLabel.textLabel.text = @"新车";
    self.totalNumLabel.text = [NSString stringWithFormat:@"%@辆",model.totalNumber];
    self.numLabel.attributedText = [YLAttributedStr changNumberColorWithTotalString:[NSString stringWithFormat:@"(SUV%@CAR%@)",model.suvNumber,model.carNumber] andColor:BlueColor];

    if ([self.model.isTransportUpload integerValue] == 0) {
        [self.tapBtn setTitle:@"运单上传" forState:UIControlStateNormal];
    }else if ([self.model.isTransportUpload integerValue] == 1) {
        [self.tapBtn setTitle:@"查看运单" forState:UIControlStateNormal];
    }else if ([self.model.isTransportUpload integerValue] == 2) {
        
    }
    cellHeight = [self.model.isTransportUpload integerValue] == 2?100:130;
}

-(void)btnDidClick:(UIButton *)button
{
    if ([button.titleLabel.text isEqualToString:@"运单上传"]){
        if (_delegate && [_delegate respondsToSelector:@selector(selectedWithUploadOrderBtn:type:)]) {
            [_delegate selectedWithUploadOrderBtn:self.model type:0];
        }
    }else{
        if (_delegate && [_delegate respondsToSelector:@selector(selectedWithUploadOrderBtn:type:)]) {
            [_delegate selectedWithUploadOrderBtn:self.model type:1];
        }
    }
}

-(UILabel *)getLabelWithFont:(NSInteger)font textAlignment:(NSTextAlignment)textAlignment
{
    UILabel *label = [[UILabel alloc]init];
    label.font = FONT(font);
    label.textAlignment = textAlignment;
    return label;
}
@end
